package com.caiden_micheal.org.web;

import com.caiden_micheal.base.aop.annotation.PermissionVerify;
import com.caiden_micheal.base.domain.AjxResult;
import com.caiden_micheal.org.domain.Org;
import com.caiden_micheal.org.service.OrgService;
import com.caiden_micheal.org.vo.*;
import com.caiden_micheal.position.domain.Position;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/org")
public class OrgController {
    @Autowired
    private OrgService orgService;

    @PermissionVerify(permissionArray = {"sys:orgManagement"})
    @PostMapping("/orgQuery")
    public AjxResult orgInfoPageQuery(@RequestBody OrgQueryVO orgQueryVO) {
        return AjxResult.success(orgService.findOrgsByCondition(orgQueryVO));
    }

    @PermissionVerify(permissionArray = {"sys:permissionManagement:assignOrg"})
    @PostMapping("/orgQueryByPermission")
    public AjxResult orgQueryByPermission(@RequestBody OrgQueryVO orgQueryVO) {
        return AjxResult.success(orgService.findOrgsByConditionPermission(orgQueryVO));
    }

    @PermissionVerify(permissionArray = {"sys:permissionManagement:assignOrg", "sys:userManagement:add", "sys:orgManagement"})
    @PostMapping("/orgSelectQuery")
    public AjxResult orgSelectQuery() {
        return AjxResult.success(orgService.findOrgSelectDatas());
    }

    @PermissionVerify(permissionArray = {"sys:orgManagement:add"})
    @PostMapping("/addOrg")
    public AjxResult addOrg(@RequestBody Org org) {
        return orgService.addOrg(org);
    }

    @PermissionVerify(permissionArray = {"sys:orgManagement:addMember"})
    @PostMapping("/addUser")
    public AjxResult addUser(@RequestBody OrgAddUserVO orgAddUserVO) {
        return orgService.updateOrgUser(orgAddUserVO);
    }

    @PermissionVerify(permissionArray = {"sys:orgManagement:edit"})
    @PostMapping("/editOrg")
    public AjxResult editOrg(@RequestBody Org org) {
        return orgService.editOrg(org);
    }

    @PermissionVerify(permissionArray = {"sys:orgManagement:addMember"})
    @PostMapping("/orgRemoveUser")
    public AjxResult orgRemoveUser(@RequestBody OrgRemoveUserVO orgRemoveUserVO) {
        return orgService.removeUser(orgRemoveUserVO.getUserId());
    }

    @PermissionVerify(permissionArray = {"sys:permissionManagement:assignOrg"})
    @PostMapping("/orgExcludePermisison")
    public AjxResult orgExcludePermission(@RequestBody OrgQueryVO orgQueryVO) {
        return AjxResult.success(orgService.excludePermission(orgQueryVO));
    }

    @PermissionVerify(permissionArray = {"sys:permissionManagement:assignOrg"})
    @PostMapping("/orgPermissionAssignment")
    public AjxResult orgPermissionAssignment(@RequestBody OrgPermissionAssignmentVO orgPermissionAssignmentVO) {
        return orgService.orgPermissionAssignment(orgPermissionAssignmentVO);
    }

    @PermissionVerify(permissionArray = {"sys:permissionManagement:assignOrg"})
    @PostMapping("/orgPermissionRemove")
    public AjxResult orgPermissionRemove(@RequestBody OrgPermissionRemoveVO orgPermissionRemoveVO) {
        return orgService.orgPermissionRemove(orgPermissionRemoveVO);
    }

    @PermissionVerify(permissionArray = {"sys:positionManagement:assignMember"})
    @PostMapping("/orgQuerySelectByPosition")
    public AjxResult orgQuerySelectByPosition(@RequestBody Position position) {
        return orgService.orgQuerySelectByPosition(position);
    }

    @PostMapping("/findOrgTree")
    public AjxResult findOrgTree() {
        return orgService.findOrgTree();
    }
}
